package edu.llg.oojcodesandbox.exception;

import edu.llg.oojcodesandbox.JavaCodeSandBoxTemplete;
import edu.llg.oojcodesandbox.model.ExecuteCodeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * LLG
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(CodeRunningException.class)
    public ExecuteCodeResult businessExceptionHandler(CodeRunningException e) {
        return JavaCodeSandBoxTemplete.packageErrorMessage(e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public ExecuteCodeResult runtimeExceptionHandler(RuntimeException e) {
        log.error("RuntimeException", e);
        return JavaCodeSandBoxTemplete.packageErrorMessage(e.getMessage());
    }
}
